package modellayer;

/**
 * If you buy a certain amount, this class makes
 * discount by subtracting a constant value from the price.
 * 
 * @author (ucn-1semprojekt-dm78-gruppe1)
 *
 */
@SuppressWarnings("serial")
public class AmountDiscount implements DiscountSubTotal
{
	private String title;
	private int begins, ends;
	private double discountFigure;

	/**
	 * @param title the description of this discount
	 * @param begins the amount where this discount begins
	 * @param ends   the amount where this discount stops
	 * @param discountFigure the figure to subtract from the price
	 */
	public AmountDiscount(String title, int begins, int ends, double discountFigure)
	{
		this.title          = title;
		this.begins         = begins;
		this.ends           = ends;
		this.discountFigure = discountFigure;
	}

	/**
	 * @param normPrice the price to be discounted (cut off)
	 * @param amount the amount or pieces to be bought. Can be used
	 * to multiply the price if used in a container subclass.
	 * @return the discounted price 
	 */
	@Override
	public double subTotal(double normPrice, int amount)
	{
		// TODO Auto-generated method stub
		if (amount >= begins && amount <= ends)
		{
			return normPrice - discountFigure;
		}
		else
		{
			return normPrice;
		}
	}
	
	/**
	 * @return a string representation of this object
	 */	
	public String toString()
	{
		return  discountFigure +" "+ title + " : " + "[" + begins + ".." + ends +"]";
	}

}
